package sdk.org.apache.shiro.G1_工具类;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.codec.Hex;

import com.titan.core.utils.data.AsciiUtils;
import com.titan.core.utils.data.AssertUtils;
import com.titan.core.utils.data.crypto.Base64Utils;
import com.titan.core.utils.debug.Timer;
import com.titan.core.utils.io.ConsoleUtils;

public class C02_编码和解码 {
    private final static String CHARSET_NAME = "UTF-8";
    
    private static void run(Timer timer) throws Exception {
        String str = "hello大大方法";
        ConsoleUtils.log("原字符串", str);
        String base64Encoded = Base64.encodeToString(str.getBytes(CHARSET_NAME));
        ConsoleUtils.log("      使用shiro的Base64工具编码", base64Encoded);
        ConsoleUtils.log("使用Base64Utils的Base64工具编码", Base64Utils.encodeToString(str, CHARSET_NAME));
        
        String str2 = Base64.decodeToString(base64Encoded);
        ConsoleUtils.log("      使用shiro的Base64工具解码", str2);
        ConsoleUtils.log("使用Base64Utils的Base64工具解码", Base64Utils.decodeToString(base64Encoded, CHARSET_NAME));

        base64Encoded = Hex.encodeToString(str.getBytes(CHARSET_NAME));
        ConsoleUtils.log("          使用shiro的Hex工具编码", base64Encoded);
        ConsoleUtils.log("使用AsciiUtils的toHexString编码", AsciiUtils.toHexString(str.getBytes(CHARSET_NAME), ""));
        ConsoleUtils.log("          使用shiro的Hex工具解码", new String(Hex.decode(base64Encoded.getBytes(CHARSET_NAME))));
        
    }
    
    
    public static void main(String[] args) {
        Timer timer = Timer.$();
        try {
            run(timer);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            timer.print("执行总用时");
            System.exit(0);
        }
    }
}
